{% from 'include/provisioning/variables.html' import gcore_regions, do_regions, aws_regions %}
{% from 'include/input_macros.html' import copy_to_clipboard %}
{% for s in servers %}
{% set region_name = [] %}
{% if s.type == 'do' %}
    {% set provider_full_name = 'DigitalOcean' %}
    {% set onclickEditAction = 'editDoServer' %}
    {% for key, value in do_regions.items() %}
        {% if s.region|int() == key|int() %}
            {% do region_name.append(value) %}
            {% endif %}
        {% endfor %}
    {% elif s.type == 'aws' %}
        {% set provider_full_name = 'AWS' %}
        {% set onclickEditAction = 'editAwsServer' %}
        {% for key, value in aws_regions.items() %}
            {% if s.region|int() == key|int() %}
                {% do region_name.append(value) %}
            {% endif %}
        {% endfor %}
    {% elif s.type == 'gcore' %}
        {% set provider_full_name = 'G-Core Labs' %}
        {% set onclickEditAction = 'editGcoreServer' %}
        {% for key, value in gcore_regions.items() %}
        {% if s.region|int() == key|int() %}
            {% do region_name.append(value) %}
        {% endif %}
    {% endfor %}
{% endif %}
<tr id="server-{{s.id}}" class="{{ loop.cycle('odd', 'even') }} {% if adding %}newserver{% endif %}">
    <td class="padding10 first-collumn">
        <span id="server-name-{{s.id}}">{{s.name}}</span>
        {% if s.type == 'gcore' and s.name_template is defined %}
            ({{s.name_template}})
        {% endif %}
    </td>
    <td style="width: 10%">
        {% for p in providers %}
            {% if p.0|int() == s.provider_id|int() %}
		        <span>{{ p.1 }}</span>
                <span id="server-provider-{{s.id}}" style="display: none;">{{p.0}}</span>
            {% endif %}
        {% endfor %}
     </td>
    {% if role == 1 %}
     <td style="width: 5%">
        {% for g in groups %}
            {% if adding %}
            {% if user_group|int() == g.group_id|int() %}
		        {{ g.name }}
		        <span id="server-group-{{s.id}}" style="display: none;">{{ g.group_id }}</span>
            {% endif %}
            {% else %}
            {% if s.group_id|int() == g.group_id|int() %}
		        {{ g.name }}
		        <span id="server-group-{{s.id}}" style="display: none;">{{ g.group_id }}</span>
            {% endif %}
            {% endif %}
        {% endfor %}
     </td>
     {% else %}
        <span id="server-group-{{s.id}}" style="display: none;">{{user_group}}</span>
     {% endif %}
    <td style="width: 10%">
        {{provider_full_name}}
        <span id="server-cloud-{{s.id}}" style="display: none;">{{s.type}}</span>
    </td>
    <td style="width: 10%">
        {{region_name.0}}
    </td>
    <td style="width: 10%">
        {% set id = "server-os-" + s.id|string() %}
        {{ copy_to_clipboard(id=id, value=s.os) }}
    </td>
    <td style="width: 15%">
        {% set id = "server-ip-" + s.id|string() %}
        {{ copy_to_clipboard(id=id, value=s.IP) }}
    </td>
    <td style="width: 10%">
        {% set id = "server-size-" + s.id|string() %}
        {{ copy_to_clipboard(id=id, value=s.instance_type) }}
    </td>
    <td style="width: 5%">
        {% if s.status == 'Created' %}
        {% set style='color: var(--green-color);' %}
        {% elif s.status == 'Error ' %}
        {% set style='color: red;cursor: help;' %}
        {% endif %}
        <span id="sever-status-{{s.id}}" title="Last error: {{s.last_error}}" style="font-weight: bold;{{style}}">{{s.status}}</span>
    </td>
    <td style="width: 100%">
        {{s.date}}
    </td>
    <td>
	    <a class="edit" onclick="{{onclickEditAction}}({{s.id}})" title="Edit server {{s.name}}" style="cursor: pointer;"></a>
	</td>
	<td>
	    <a class="delete" onclick="confirmDeleteProvisionedServer({{s.id}})" title="Delete server {{s.name}}" style="cursor: pointer;"></a>
    </td>
</tr>
{% endfor %}